package net.cn_su.sharpeyes;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    List<TextView> mRadioButtons = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_add_pinjia);

        LinearLayout ll_01 = (LinearLayout) findViewById(R.id.ll_01);
        LinearLayout ll_02 = (LinearLayout) findViewById(R.id.ll_02);
        LinearLayout ll_03 = (LinearLayout) findViewById(R.id.ll_03);
        LinearLayout ll_04 = (LinearLayout) findViewById(R.id.ll_04);

        final TextView rb01 = (TextView) findViewById(R.id.rb_01);
        final TextView rb02 = (TextView) findViewById(R.id.rb_02);
        final TextView rb03 = (TextView) findViewById(R.id.rb_03);
        final TextView rb04 = (TextView) findViewById(R.id.rb_04);

        mRadioButtons.add(rb01);
        mRadioButtons.add(rb02);
        mRadioButtons.add(rb03);
        mRadioButtons.add(rb04);


        ll_01.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPoistion(rb01);
            }
        });
        ll_02.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPoistion(rb02);
            }
        });
        ll_03.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPoistion(rb03);
            }
        });
        ll_04.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPoistion(rb04);
            }
        });
    }

    private void selectPoistion(TextView rb) {
        for (TextView tv : mRadioButtons) {
            if (tv == rb) {
                tv.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_circle_bule));
                tv.setTextColor(getResources().getColor(R.color.white));
            } else {
                tv.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_circle_white));
                tv.setTextColor(getResources().getColor(R.color.text_black));
            }

        }

    }


}
